package com.blog.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blog.user.entity.UserAttention;
import com.blog.user.entity.UserCollection;
import com.blog.user.mapper.UserAttentionMapper;
import com.blog.user.service.UserAttentionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zw
 * @since 2021-12-08
 */
@Service
public class UserAttentionServiceImpl extends ServiceImpl<UserAttentionMapper, UserAttention> implements UserAttentionService {

    @Autowired
    UserAttentionMapper userAttentionMapper;


    @Override
    public boolean isAttented(String userId, String userAttentionId) {
        QueryWrapper<UserAttention> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId).eq("user_attention_id",userAttentionId);
        UserAttention userAttention = this.getOne(queryWrapper);
        if(userAttention == null)
            return  false;
        else
            return true;

    }

    @Override
    public void insertAttention(String userId, String userAttentionId) {
        UserAttention userAttention=new UserAttention();
        userAttention.setUserId(userId);
        userAttention.setUserAttentionId(userAttentionId);
        userAttentionMapper.insert(userAttention);

    }

    @Override
    public void pageQuery(Page<UserAttention> pageInfo, String userId) {
        if(userId == null||userId.isEmpty())
            return ;
        QueryWrapper<UserAttention> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId).orderBy(true,true,"id");
        this.page(pageInfo,queryWrapper);
    }
}
